package mlp.game.scootaloo;

import com.overkill.game.GameEngine;
import com.overkill.game.Sprite;
import com.overkill.game.SpriteRenderable;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;

public class Background extends SpriteRenderable {
	
	public Background(Sprite sprite) {
		super(sprite);
	}
	
	@Override
	public void update(long gameTime) {	
		moveXBy(ScootalooEngine.GAME_SPEED);
		if(getPosition().x > getWidth()){
			moveX(0);
		}
		super.update(gameTime);
	}

	@Override
	public void draw(Canvas canvas) {
		canvas.drawColor(Color.BLACK);
		Rect dst1 = GameEngine.getStage();
		Rect src1 = new Rect((int)(getPosition().x), 0, (int)(getPosition().x + GameEngine.getStage().width()), getHeight());
		canvas.drawBitmap(getSprite().getBitmap(), src1, dst1, null); 
		if(src1.right > GameEngine.getStage().width()){
			Rect src2 = new Rect((int)(getPosition().x - getWidth()), 0, (int)(getPosition().x - getWidth() + GameEngine.getStage().width()), getHeight());
			canvas.drawBitmap(getSprite().getBitmap(), src2, dst1, null);
		}
	}
	
}
